package com.eric.dao;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eric.dao.mapper.SchoolMapper;
import com.eric.dos.SchoolDO;
import org.springframework.stereotype.Service;

/**
 * @description:
 * @author: liuBing
 * @create: 2022-10-31 18:33
 **/
@Service
public class SchoolDAO extends ServiceImpl<SchoolMapper, SchoolDO> {


    public void update(String id, String name) {

        // 方式一
        LambdaUpdateWrapper<SchoolDO> Wrapper = Wrappers.lambdaUpdate();
        Wrapper.eq(SchoolDO::getId,id);
        Wrapper.set(SchoolDO::getName,name);
        update(Wrapper);


        // 方式二
        update(
                Wrappers.<SchoolDO>lambdaUpdate()
                        .eq(SchoolDO::getId, id)
                        .set(SchoolDO::getName, name)
        );

        // 方式三
        lambdaUpdate()
                .set(SchoolDO::getName, name)
                .eq(SchoolDO::getId, id)
                .update();

        // 方式四
        new LambdaUpdateChainWrapper<>(getBaseMapper())
                .eq(SchoolDO::getId, id)
                .set(SchoolDO::getName, name);

    }
}
